﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IGolovkine.ShoutCastRipper;
using IGolovkine.Core.Diagnostics;

namespace IGolovkine.ShoutCastRipper.Service
{
    public class ConsoleLogWriter : ILogWriter
    {
        private string _name;
        public ConsoleLogWriter(string name)
        {
            _name = name;
        }
        public void WriteLine(string format, params object[] args)
        {
            string message = string.Format(format, args);
            Console.WriteLine(AppendTimeStamp(message));
        }

        public void WriteLine()
        {
            Console.WriteLine();
        }

        public void WriteLine(string message)
        {
            Console.WriteLine(AppendTimeStamp(message));
        }

        private string AppendTimeStamp(string message)
        {
            return string.Format("[{0:HH:mm:ss}] {1}: ", DateTime.Now, _name) + message;
        }

        public void WriteException(string message, Exception ex)
        {
            ConsoleColor color = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine();
            Console.WriteLine(AppendTimeStamp(message));
            Console.WriteLine("### EXCEPTION ### " + ex.Message);
            Console.ForegroundColor = color;
            Console.WriteLine();
        }

        #region ILogWriter Members

        public void WriteDebug(string format, params object[] args)
        {
#if DEBUG
            this.WriteLine("%DEBUG% " + string.Format(format, args));
#endif
        }

        #endregion
    }
}
